﻿using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;

// Token: 0x02000020 RID: 32
public class ParasiteScript : MonoBehaviour
{
	// Token: 0x0600008A RID: 138 RVA: 0x0000E11F File Offset: 0x0000C31F
	private void Start()
	{
		this.vol = Camera.main.GetComponent<Volume>();
		this.vol.profile.TryGet<ColorAdjustments>(out this.adj);
	}

	// Token: 0x0600008B RID: 139 RVA: 0x0000E148 File Offset: 0x0000C348
	private void Update()
	{
		this.cooldown -= Time.deltaTime;
		if (this.cooldown < 0f && !this.didFlash)
		{
			this.didFlash = true;
			this.adj.postExposure.value += 1.5f;
		}
		if (this.cooldown < -25f)
		{
			GameManager.main.playerBody.health = -1f;
		}
		if (this.cooldown > -19f)
		{
			this.adj.postExposure.value -= Time.deltaTime * 1.5f;
			this.adj.postExposure.value = Mathf.Clamp(this.adj.postExposure.value, 0f, 2.2f);
		}
		else
		{
			this.adj.postExposure.value += Time.deltaTime * 0.3f;
		}
		if (Input.GetKeyDown(KeyCode.G) && GameManager.main.playerBody.alive && this.cooldown < 0f)
		{
			Collider2D collider2D = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.25f);
			DamageReceiver damageReceiver;
			if (collider2D && collider2D.TryGetComponent<DamageReceiver>(out damageReceiver) && damageReceiver.body != GameManager.main.playerBody && damageReceiver.body.health > 0f)
			{
				this.cooldown = 25f;
				this.didFlash = false;
				this.adj.postExposure.value += 1.6f;
				damageReceiver.body.gameObject.AddComponent<PlayerInput>();
				if (BloodDamageUI.main)
				{
					BloodDamageUI.main.body = damageReceiver.body;
					BloodDamageUI.main.playedCorpusSound = false;
					BloodDamageUI.main.lowHealthAudio.Play();
				}
				if (CameraController.main)
				{
					CameraController.main.checkTransform = damageReceiver.body.torso.transform;
				}
				if (MusicManager.main)
				{
					MusicManager.main.body = damageReceiver.body;
				}
				if (damageReceiver.body.GetComponent<AI>())
				{
					Object.Destroy(damageReceiver.body.GetComponent<AI>());
				}
				Object.Destroy(GameManager.main.playerBody.GetComponent<PlayerInput>());
				Object.Destroy(GameManager.main.playerBody.GetComponent<HealthRegen>());
				GameManager.main.playerBody.health = -1f;
				GameManager.main.playerBody.gameObject.AddComponent<VrBuddyDeathBehaviour>();
				switch (PlayerPrefs.GetInt("difficulty"))
				{
				case 0:
					damageReceiver.body.overallForce += 1.5f;
					damageReceiver.body.attackTimeMult += 0.5f;
					damageReceiver.body.health /= 0.3f;
					damageReceiver.body.maxHealth /= 0.3f;
					damageReceiver.body.hitStunMult -= 1.5f;
					break;
				case 1:
					damageReceiver.body.overallForce += 0.8f;
					damageReceiver.body.attackTimeMult += 0.25f;
					damageReceiver.body.health /= 0.5f;
					damageReceiver.body.maxHealth /= 0.5f;
					damageReceiver.body.hitStunMult -= 0.8f;
					break;
				case 2:
					damageReceiver.body.health /= 0.75f;
					damageReceiver.body.maxHealth /= 0.75f;
					break;
				}
				damageReceiver.body.overallForce += (float)PlayerPrefs.GetInt("up1") * 0.06f;
				damageReceiver.body.attackTimeMult += (float)PlayerPrefs.GetInt("up1") * 0.01f;
				damageReceiver.body.moveForce += (float)PlayerPrefs.GetInt("up2") * 2f;
				damageReceiver.body.maxSpeed += (float)PlayerPrefs.GetInt("up2") * 0.2f;
				damageReceiver.body.turnSpeed += (float)PlayerPrefs.GetInt("up2") * 0.02f;
				damageReceiver.body.jumpForce += (float)PlayerPrefs.GetInt("up2") * 0.35f;
				damageReceiver.body.health += (float)PlayerPrefs.GetInt("up3") * 4f;
				damageReceiver.body.maxHealth += (float)PlayerPrefs.GetInt("up3") * 4f;
				damageReceiver.body.hitStunMult -= (float)PlayerPrefs.GetInt("up5") * 0.02f;
				damageReceiver.body.team = "goodguys";
				damageReceiver.body.gameObject.AddComponent<HealthRegen>().hpPerSec = GameManager.main.PlayerRegenByDifficulty();
				if (GameManager.main.bodies.Contains(damageReceiver.body))
				{
					GameManager.main.bodies.Remove(damageReceiver.body);
				}
				HankScript hankScript;
				if (damageReceiver.body.TryGetComponent<HankScript>(out hankScript))
				{
					hankScript.HankKilled();
				}
				GameManager.main.playerBody = damageReceiver.body;
				Sound.Play(Resources.Load<AudioClip>("Sounds/transfer" + Random.Range(1, 4).ToString()), Vector2.zero, true, false, 1f);
				Sound.Play(Resources.Load<AudioClip>("Sounds/instaSwitch"), Vector2.zero, true, false, 1f);
			}
		}
		if (this.cooldown > 0f)
		{
			this.circleImage.fillAmount = 1f - this.cooldown / 25f;
			this.circleImage.color = new Color(1f, 1f, 1f, 0.5f);
			this.parasiteImage.color = new Color(1f, 1f, 1f, 0.5f);
			return;
		}
		this.circleImage.fillAmount = -this.cooldown / 19f;
		this.circleImage.color = new Color(1f, 0.7f, 0.7f, 0.5f);
		this.parasiteImage.color = new Color(1f, 0.7f, 0.7f, 0.5f);
	}

	// Token: 0x04000163 RID: 355
	public float cooldown;

	// Token: 0x04000164 RID: 356
	private Volume vol;

	// Token: 0x04000165 RID: 357
	private ColorAdjustments adj;

	// Token: 0x04000166 RID: 358
	private bool didFlash;

	// Token: 0x04000167 RID: 359
	public Image parasiteImage;

	// Token: 0x04000168 RID: 360
	public Image circleImage;
}
